<?php

	function countNumAndChars( &$numCounter, &$charCounter, $password )
	{
		if ( !empty( $password ) )
		{
			$len = strlen( $password );
			$arr = str_split( $password );
			for($i = 0; $i < $len; $i++)
			{
				if( ($arr[$i] >= '0') && ($arr[$i] <= '9') )			
				{
					$numCounter++;
				}
				else
				{
					if( ( ($arr[$i] >= 'a') && ($arr[$i] <= 'z') ) || ( ($arr[$i] >= 'A') && ($arr[$i] <= 'Z') ) )
					{
						$charCounter++;
					}
				}
			}
		}
		else
		{
			$numCounter = -1;
			$charCounter = -1;
		}
	}

	function getSafety( $password )
	{
		$numCounter = 0;
		$charCounter = 0;
		countNumAndChars( $numCounter, $charCounter, $password );
		
		if( $numCounter + $charCounter == 0)
		{
			$safety = -1;
		}
		else if( $numCounter + $charCounter == -2)
		{
			$safety = 0;
		}
		else
		{
			if($charCounter == 0)
			{
				if( $numCounter >= 10 )
				{
					$safety = 2;
				}
				else
				{
					$safety = 1;
				}
			}
			else
			{
				if($numCounter == 0)
				{
					if( $charCounter >= 10 )
					{
						$safety = 2;
					}
					else
					{
						$safety = 1;
					}
				}
				else
				{
					if($numCounter + $charCounter >= 8)
					{
						$safety = 2;
					}
					if($numCounter + $charCounter >= 12)
					{
						$safety = 3;
					}
				}
			}
		}
		return $safety;
	}

?>